<?php

class StorageSystem extends BaseModel 
{
    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'storage_system';
    }
    
 	public function rules()
    {
        return array(
            array('host_name, storage_type, namespace, client_home', 'required', 'message'=>'{attribute} 不能为空'),
        );
    }

    /**
     *
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'system_id' => '编号',
            'host_name' => '主机名称',
            'port' => '端口',
            'user_name' => '用户名',
            'password' => '密码',
            'storage_type'   => '类型',
            'namespace' =>  '命名空间',
        	'client_home' =>  '客户端',
        );
    }

    public static function listItems($type=array()) 
    {
        $criteria = new CDbCriteria;
        if(count($type) > 0) {
        	$criteria->addInCondition('storage_type', $type);
        }
        $storages = self::model()->findAll($criteria);

        $items = array();
        foreach($storages as $storage) {
            $type = PhysicalType::$names[$storage['storage_type']];
            $items[$storage['system_id']] = "{$type} | {$storage['host_name']} | {$storage['namespace']}";
        }
        return $items;
    }
 }
